﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="LoadOrder.aspx.cs" Inherits="iMall.AtoZ.LoadOrder" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        body
        {
            font-family: Verdana, Geneva, sans-serif;
            font-size: 13px;
            color: #333;
            background: url(/Scripts/plupload/examples/bg.jpg);
        }
        .reslutTD
        {
            border: solid #000 1px;
        }
        #Merchant
        {
            width: 93px;
        }
    </style>
    <link rel="stylesheet" href="/Scripts/jquery-ui-1.8.16/css/base/jquery.ui.all.css"
        type="text/css" />
    <link rel="stylesheet" href="/Scripts/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css"
        type="text/css" />
    <script type="text/javascript" src="/Scripts/jquery-ui-1.8.16/js/jquery-ui-1.8.16.all.min.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/browserplus-min.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.gears.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.silverlight.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.flash.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.browserplus.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.html4.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/plupload.html5.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
    <script type="text/javascript" src="/Scripts/plupload/js/i18n/cn.js"></script>
    <script type="text/javascript">
        function newGuid() {
            var guid = "";
            for (var i = 1; i <= 32; i++) {
                var n = Math.floor(Math.random() * 16.0).toString(16);
                guid += n;
                if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
                    guid += "-";
            }
            return guid;
        }

        function getCurrentDirectory() {
            var locHref = location.href;
            var locArray = locHref.split("/");
            delete locArray[locArray.length - 1];
            var dirTxt = locArray.join("/");
            return dirTxt;
        }

        var bn = newGuid();
        var totalFile = 0;
        $(function () {
            // 初始化Flash上传插件$("#flash_uploader").(pluploadQueue)--old
            $("#flash_uploader").plupload({
                runtimes: 'flash,html5,browserplus,silverlight,gears,html4', 	//使用Flash插件
                url: '/Scripts/plupload/upload.aspx', 	//服务器端响应页面
                max_file_size: '100mb', //最大文件限制
                chunk_size: '1mb', 	//一次上传数据大小
                unique_names: false, 	//是否自动生成唯一名称
                filters: [				//文件类型限制
				{title: "Excel（xls,xlsx)", extensions: "xls,xlsx" }
			],
                // 缩放图片
                //resize: { width: 320, height: 240, quality: 80 },

                // Rename files by clicking on their titles
                rename: true,

                // Sort files
                sortable: true,

                // SWF文件位置
                flash_swf_url: '/Scripts/plupload/js/plupload.flash.swf',

                // Silverlight settings
                silverlight_xap_url: '/Scripts/plupload/js/plupload.silverlight.xap',

                init: {
                    FileUploaded: function (up, file, info) {
                        var Merchant = $("#Merchant").find("option:selected").text();
                        var fileInfo = '{"name":"' + file.name + '","path":"' + info.response + '","size":"' + file.size + '","Merchant":"' + Merchant + '","batchNum":"' + bn + '"}';
                        var bii = newGuid();
                        ImpAccessData(bii, file.name);
                        SaveData(fileInfo, bii);
                    },

                    Error: function (up, args) {
                        //发生错误
                        if (args.file) {
                            alert('[出错啦] 文件:' + args.file);
                        } else {
                            alert('[出错啦]' + args);
                        }
                    }
                }
            });
            alert("OK");
            //init merchant
            BindMerchant();
        });

        function SaveData(data, id) {
            var fileInfo = 'data=' + data;
            var mi = $("#Merchant").val();
            $.ajax({
                type: "POST",
                url: "/DoPost/DoSaveOrder.ashx", //LoadOrder.aspx
                datatype: "json", //请求页面返回的数据类型  
                data: fileInfo,
                async: false,
                //contentType: "application/json", //注意请求页面的contentType
                beforeSend: function (XMLHttpRequest) {
                    //do beforeSend
                },
                success: function (data, status) {
                    //var dataObj = eval("(" + data + ")")
                    LoadOrderResult(data, id);
                },
                complete: function (XMLHttpRequest, status) {
                    //do complete
                },
                error: function (XMLHttpRequest, status, errorThrown) {
                    alert(errorThrown);
                }
            });
        }

        function BindMerchant() {
            $.ajax({
                type: "POST",
                url: "/DoPost/DoPost.aspx?t=1", //LoadOrder.aspx
                datatype: "json", //请求页面返回的数据类型  
                data: {},
                //contentType: "application/json", //注意请求页面的contentType
                beforeSend: function (XMLHttpRequest) {
                    //do beforeSend
                },
                success: function (data, status) {
                    var dataObj = eval("(" + data + ")");
                    for (var i = 0; i < dataObj.length; i++) {
                        $("#Merchant").append('<option value="' + dataObj[i].ID + '">' + dataObj[i].MerchantName + '</option>');
                    }
                    //alert(data);
                },
                complete: function (XMLHttpRequest, status) {
                    //do complete
                },
                error: function (XMLHttpRequest, status, errorThrown) {
                    alert(errorThrown);
                }
            });
        }
        function LoadOrderResult(data, name) {
            $("#" + name).append(data);
        }

        function ImpAccessData(id, path) {
            totalFile++;
            $("#result").append("<tr id=\"" + id + "\"><td class=\"reslutTD\">" + totalFile + "</td><td class=\"reslutTD\">" + path + '</td><td class=\"reslutTD\">已上传</td></tr>');
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div style="margin-top: 20px">
        <select id="Merchant">
        </select>
        <div id="flash_uploader" style="width: 700px; height: 320px;">
            您没有安装Flash！</div>
        <div>
            <table id="result" style="border: 2px; border-collapse: collapse; border: solid #000 1px;
                width: 700px; border-spacing: inherit; empty-cells: show;">
                <colgroup>
                    <col width="30px" />
                    <col width="380px" />
                    <col width="55px" />
                    <col width="65px" />
                </colgroup>
                <tr>
                    <td class="reslutTD">
                        序号
                    </td>
                    <td class="reslutTD">
                        文件
                    </td>
                    <td class="reslutTD">
                        上传状态
                    </td>
                    <td class="reslutTD">
                        导入状态
                    </td>
                    <td class="reslutTD">
                        导入结果
                    </td>
                    <td class="reslutTD">
                        合法数据
                    </td>
                    <td class="reslutTD">
                        所有数据
                    </td>
                </tr>
            </table>
        </div>
    </div>
</asp:Content>